#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int sample_atoi(char *s)
{
	int sign = 1, num = 0;

	if ( *s == '-' )
		sign = -1;

	while ( *s != '\0' && *s <= '9') {
		num = num * 10 + ( *s - '0' );
		s++;
	}

	return num * sign;
}


int main()
{
	char buf[4] = "123";
	int dec;

	dec = atoi(buf);
	printf("%d\n", dec);

	dec = sample_atoi(buf);
	printf("%d\n", dec);

	return 0;
}

